//
//  DNPickerView.m
//  DanoneEA
//
//  Created by Senela on 16/11/1.
//  Copyright © 2016年 翔傲科技. All rights reserved.
//

#import "DNPickerView.h"

 
@interface DNPickerView()<UIPickerViewDelegate, UIPickerViewDataSource>
{
    NSInteger selectRow;
}
@end

@implementation DNPickerView

/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect {
    // Drawing code
}
*/

// 自定义显示的字体大小及样式
//- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view
//{
//    UILabel* pickerLabel = (UILabel*)view;
//    if (!pickerLabel)
//    {
//        pickerLabel = [[UILabel alloc] init];
//        // Setup label properties - frame, font, colors etc
//        //adjustsFontSizeToFitWidth property to YES
//        pickerLabel.minimumScaleFactor = 8.;
//        pickerLabel.adjustsFontSizeToFitWidth = YES;
//        [pickerLabel setTextAlignment:NSTextAlignmentLeft];
//        [pickerLabel setBackgroundColor:[UIColor clearColor]];
//        [pickerLabel setFont:[UIFont boldSystemFontOfSize:15]];
//    }
//    // Fill the label text here
////    pickerLabel.text=[self pickerView:pickerView viewForRow:row forComponent:component reusingView:<#(UIView *)#>]
//    return pickerLabel;
//}

-(void)setArrPickerData:(NSArray *)arrPickerData
{
    _arrPickerData = arrPickerData;
    self.dataSource = self;
    self.delegate = self;
    [self reloadAllComponents];
}

#pragma mark - UIPickerViewDataSource

//返回多少列
- (NSInteger)numberOfComponentsInPickerView:(UIPickerView *)pickerView {
    return _arrPickerData.count;
}

//每列对应多少行
- (NSInteger)pickerView:(UIPickerView *)pickerView numberOfRowsInComponent:(NSInteger)component {
    return [_arrPickerData[component] count];
}

//每行显示的数据
- (NSString *)pickerView:(UIPickerView *)pickerView titleForRow:(NSInteger)row forComponent:(NSInteger)component{
    
    NSArray *componentArr = _arrPickerData[component];
    return componentArr[row];
}


#pragma mark - UIPickerViewDelegate
//- (CGFloat)pickerView:(UIPickerView *)pickerView widthForComponent:(NSInteger)component
//{
//    if(_widthForComponentArr == nil)
//        return 44;
//    else
//    {
//        NSString *width = _widthForComponentArr[component];
//        return width.floatValue;
//    }
//}

//选中pickerView的某一行
- (void)pickerView:(UIPickerView *)pickerView didSelectRow:(NSInteger)row inComponent:(NSInteger)component
{
    selectRow = row;
    
    if (self.selectBlock) {
        self.selectBlock(component, row);
    }
    
    if(_autoHide)
        [self dismissPickerView];
    
}

#pragma mark - Private Menthods

//弹出pickerView
- (void)popPickerView
{
    [UIView animateWithDuration:0.5
                     animations:^{
                         self.frame = CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGHT);
                     }];
    
}

//取消pickerView
- (void)dismissPickerView
{
    [UIView animateWithDuration:0.5
                     animations:^{
                         self.frame = CGRectMake(0, SCREEN_HEIGHT, SCREEN_WIDTH, SCREEN_HEIGHT);
                     }];
}


@end
